package com.saibowisdom.storage.aspirator.common.meta;

import java.io.Serializable;

public class FieldInfo implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = -4687196131454962744L;
    /**
     * 表名
     */
    String table;
    /**
     * 字段名
     */
    String field;
    /**
     * 字段类型
     */
    int dataType;
    boolean primkey;
    int compositePrimkey;
    int indexed;
    boolean stored;
    boolean docValues;
    boolean mulValues;
    boolean cleanHtml;
    //0-不分区,1-按天分区,2-按月分区,3-按年分区
    private int partitionType;
    private int b2i(boolean b) {
        if (b)
            return 1;
        return 0;
    }

    @Override
    public int hashCode() {
        return table.hashCode() + field.hashCode() + compositePrimkey + indexed * 1000 + b2i(stored) * 100 + b2i(docValues) * 10 + b2i(mulValues) * 5 + b2i(primkey) + dataType;

    }

    public String getTable() {
        return table;
    }

    public void setTable(String table) {
        this.table = table;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public int getDataType() {
        return dataType;
    }


    public String getDataTypeString(String type) {
        String re;

        /*switch (dataType) {
            case 1:

                re = "string";
                break;
            case 2:
                re = "integer";
                break;
            case 3:
                re = "float";
                break;
            case 4:
                re = "date";
                break;
            case 5:
                re = "long";
                break;
        }
        if (type.equals("hbase")) {
            switch (dataType) {
                case 1:
                    re = "varchar";
                    break;
                case 2:
                    re = "INTEGER";
                    break;
                case 3:
                    re = "float";
                    break;
                case 4:
                    re = "date";
                    break;
                case 5:
                    re = "bigint";
                    break;
            }
        }*/

        switch (dataType) {
            case 1:

                re = "string";
                if (type.equals("hbase")) {
                    re = "varchar";
                }
                break;
            case 2:
                re = "integer";
                if (type.equals("hbase")) {
                    re = "INTEGER";
                }
                break;
            case 3:
                re = "float";
                break;
            case 4:
                re = "date";
                break;
            case 5:
                re = "long";
                if (type.equals("hbase")) {
                    re = "bigint";
                }
                break;
            default:
                return null;
        }
        return re;
    }

    public void setDataType(int dataType) {
        this.dataType = dataType;
    }

    public boolean isPrimkey() {
        return primkey;
    }

    public void setPrimkey(boolean primkey) {
        this.primkey = primkey;
    }

    public int getCompositePrimkey() {
        return compositePrimkey;
    }

    public void setCompositePrimkey(int compositePrimkey) {
        this.compositePrimkey = compositePrimkey;
    }

    public int getIndexed() {
        return indexed;
    }

    public void setIndexed(int indexed) {
        this.indexed = indexed;
    }

    public boolean isStored() {
        return stored;
    }

    public void setStored(boolean stored) {
        this.stored = stored;
    }

    public boolean isDocValues() {
        return docValues;
    }

    public void setDocValues(boolean docValues) {
        this.docValues = docValues;
    }

    public boolean isMulValues() {
        return mulValues;
    }

    public void setMulValues(boolean mulValues) {
        this.mulValues = mulValues;
    }

    public boolean isCleanHtml() {
        return cleanHtml;
    }

    public void setCleanHtml(boolean cleanHtml) {
        this.cleanHtml = cleanHtml;
    }

    public int getPartitionType() {
        return partitionType;
    }

    public void setPartitionType(int partitionType) {
        this.partitionType = partitionType;
    }
}
